package com.gdglc.spring.biz.impl.auth;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.core.env.SystemEnvironmentPropertySource;
import org.springframework.security.config.annotation.authentication.configurers.userdetails.DaoAuthenticationConfigurer;

import com.gdglc.spring.biz.auth.ISysroleBiz;
import com.y2.authprj.bean.auth.model.Page;
import com.y2.authprj.bean.auth.model.SysroleInfo;
import com.y2.authprj.bean.auth.vo.UserroleVo;
import com.y2.authprj.bean.auth.vo.showSysroleAndRoleAuthorityVo;
import com.y2.authprj.dao.auth.ISysroleDao;
import com.y2.authprj.exception.BizException;

public class SysroleBizImpl implements ISysroleBiz{

	private ISysroleDao dao2;
	
	

	public ISysroleDao getDao2() {
		return dao2;
	}

	public void setDao2(ISysroleDao dao2) {
		this.dao2 = dao2;
	}

	@Override
	public List<SysroleInfo> findAllSysrole() {
		// TODO Auto-generated method stub

		return dao2.findAllSysrole();
	}

	@Override
	public int addSysrole(SysroleInfo sysroleInfo) {
		sysroleInfo.setCreateTime(new Date());
		sysroleInfo.setDeleteFlag(1);
		sysroleInfo.setMangerroleFlag(1);
		return dao2.addSysrole(sysroleInfo);
	}

	@Override
	public void deleteSysrole(int id) {
		// TODO Auto-generated method stub
		dao2.deleteSysrole(id);
	}

	@Override
	public int updateSysrole(SysroleInfo sysroleInfo) {
		return dao2.updateSysrole(sysroleInfo);
	}
	
	public static void main(String[] args) {
		SysroleBizImpl impl=new SysroleBizImpl();
		List<SysroleInfo> sysroleInfos=impl.findAllSysrole();
		for(SysroleInfo s:sysroleInfos){
			System.out.println(s.getCreateTime());
		}
	}
	
	
	@Override
	public List<showSysroleAndRoleAuthorityVo> findSysroleAndRoleAuthority() {
		return dao2.findSysroleAndRoleAuthority();
	}

	@Override
	public SysroleInfo findSysroleByRoleId(int roleId) {
		// TODO Auto-generated method stub
		return dao2.findSysroleByRoleId(roleId);
	}

	@Override
	public SysroleInfo findSysroleByRoleId(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<showSysroleAndRoleAuthorityVo> findSysroleAndRoleAuthorityBySysId(int roleId) {
		// TODO Auto-generated method stub
		return dao2.findSysroleAndRoleAuthorityBySysId(roleId);
	}

	
	
	
	@Override
	public SysroleInfo findById(int id) {
		// TODO Auto-generated method stub
		return dao2.findById(id);
	}

	@Override
	public Page<SysroleInfo> showSysroleInfo(UserroleVo vo) throws BizException {
		Page<SysroleInfo> sysPage=new Page<SysroleInfo>();
		try{
			int count=dao2.findCount(vo);
			List<SysroleInfo> sysroleList = dao2.findBySysrole(vo);
			
			sysPage.setTotalCount(count);
			sysPage.setPageSize(vo.getNum());
			sysPage.setCurrPageNo(vo.getPageNum());
			int totalPage=(count%vo.getNum()==0)?(count/vo.getNum()):(count/vo.getNum())+1;
			//总页数
			sysPage.setTotalPageCount(totalPage);
			
			
			if(null==sysroleList){
				sysroleList = new ArrayList<SysroleInfo>();
			}
			sysPage.setList(sysroleList);
			return sysPage;
		}catch(Exception e){
			throw new BizException("查询失败");
		}
	}
}
